﻿@using System.ComponentModel.DataAnnotations;
@using System.Text.Json;

<Form 
    Model="@model"
    Layout="FormLayout.Vertical"
    ValidateMode="FormValidateMode.Complex"
    RequiredMark="@ChosenRequiredMark">
    <FormItem>
        <RadioGroup @bind-Value="@ChosenRequiredMark">
            <Radio RadioButton Value="FormRequiredMark.Required">Required</Radio>
            <Radio RadioButton Value="FormRequiredMark.Optional">Optional</Radio>
            <Radio RadioButton Value="FormRequiredMark.None">None</Radio>
        </RadioGroup>
    </FormItem>
    <FormItem Label="Required By Parameter" Required>
        <Input @bind-Value="@context.RequiredByParameter" />
    </FormItem>
    <FormItem Label="Required By Rule Field" Rules="@(new FormValidationRule[]{ new FormValidationRule{ Required = true } })">
        <Input @bind-Value="@context.RequiredByRule" />
    </FormItem>
    <FormItem Label="Required By Data Attribute" Tooltip="This is a required field">
        <Input @bind-Value="@context.RequiredByDataAttribute" />
    </FormItem>
    <FormItem Label="Optional">
        <Input @bind-Value="@context.Optional" />
    </FormItem>
</Form>

@code
{
    public FormRequiredMark ChosenRequiredMark { get; set; } = FormRequiredMark.Required;

    public class Model
    {
        public string Optional { get; set; }

        public string RequiredByParameter { get; set; }

        public string RequiredByRule { get; set; }

        [Required]
        public string RequiredByDataAttribute{ get; set; }
    }

    private Model model = new Model();
}